package htmlAnalysis;


import com.google.gson.Gson;
import entity.AccidentManage;

import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.HashSet;

/**
 * 描述:
 *
 * @author yanzhengwu
 * @create 2020-12-28 10:46
 */
public class HtmlUtil<T> {

    public static class MyTypeToken<T> {
        Type mType;

        protected MyTypeToken() {
            ParameterizedType parameterizedType = (ParameterizedType) getClass().getGenericSuperclass();
            mType = parameterizedType.getActualTypeArguments()[0];
        }

        public Type getType() {
            return mType;
        }
    }


    private Class<?> clazz;
    private T entity;
    private Type type1;


    public HtmlUtil() {

    }

    private HtmlUtil(T entity) {
        this.entity = entity;
        this.clazz = entity.getClass();
        type1 = new MyTypeToken<T>() {
        }.getType();

    }

    public Type getType1() {
        return type1;
    }

    /**
     * 屏蔽bean参数
     */
    private HashSet<String> shieldProperty = new HashSet<String>();

    /**
     * 预存标签内属性
     */
    private HashMap<String, Object> attribute = new HashMap();
    /**
     * 预存bean参数
     */
    private HashSet<String> entityProperty = new HashSet<String>();

    public void setShieldProperty(String property) {
        shieldProperty.add(property);
    }

    public void removeShieldProperty(String property) {
        shieldProperty.remove(property);
    }

    public HashSet<String> getShieldProperty() {
        return this.shieldProperty;
    }

    public HashSet<String> getEntityProperty() {
        return this.entityProperty;
    }

    /**
     * 处理标签属性列表
     */
    public void operationAttribute() {

        System.out.println(clazz.getTypeName());

    }

    /**
     * 预存bean属性
     */
    public void formatEntity() {

        Field[] fields = clazz.getDeclaredFields();
        for (Field field : fields) {
            if (!"serialVersionUID".equals(field.getName())) {
                if (!shieldProperty.contains(field.getName())) {
                    entityProperty.add(field.getName());
                }
            }

        }
    }

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        HtmlUtil<AccidentManage> htmlUtil = new HtmlUtil(new AccidentManage());
        Gson gson = new Gson();
       /* Type type1 = new MyTypeToken<AccidentManage>() {
        }.getType();*/
        Type type1 = htmlUtil.getType1();
        System.out.println(type1);
        //System.out.println("ClassName=>"+Class.forName("/**.AccidentManage").getName());
        /*System.out.println(htmlUtil.getClass().getResource("TableTr"));
        Class accidentManage = AccidentManage.class;
        Class tableTr = TableTr.class;
        String name = accidentManage.getName();
        System.out.println("accidentManage==>" + name);
        String className = tableTr.getName().replace('.', '/');
        System.out.println("accidentManage==>" + tableTr.getName());
        System.out.println("accidentManage==>" + className);

        Class newClass = Class.forName(tableTr.getName());
        Object o=  newClass.newInstance();
        System.out.println(o.getClass().getName());*/
        //HtmlUtil <AccidentManage>htmlUtil = new HtmlUtil();
        //htmlUtil.operationAttribute();
        //htmlUtil.setShieldProperty("id");
        //htmlUtil.formatEntity();
        /*for (String str : htmlUtil.getEntityProperty()) {
            System.out.println(str);
        }*/


    }


}
